package com.menggudf.service.impl;

import com.menggudf.entity.MedicalDbDetail;
import com.menggudf.mapper.MedicalDbDetailDao;
import com.menggudf.service.MedicalDbDetailService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * (MedicalDbDetail)表服务实现类
 *
 * @author makejava
 * @since 2025-02-20 16:58:29
 */
@Service("medicalDbDetailService")
public class MedicalDbDetailServiceImpl implements MedicalDbDetailService {
    @Resource
    private MedicalDbDetailDao medicalDbDetailDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public MedicalDbDetail queryById(Integer id) {
        return this.medicalDbDetailDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param medicalDbDetail 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<MedicalDbDetail> queryByPage(MedicalDbDetail medicalDbDetail, PageRequest pageRequest) {
        long total = this.medicalDbDetailDao.count(medicalDbDetail);
        return new PageImpl<>(this.medicalDbDetailDao.queryAllByLimit(medicalDbDetail, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param medicalDbDetail 实例对象
     * @return 实例对象
     */
    @Override
    public MedicalDbDetail insert(MedicalDbDetail medicalDbDetail) {
        this.medicalDbDetailDao.insert(medicalDbDetail);
        return medicalDbDetail;
    }

    /**
     * 修改数据
     *
     * @param medicalDbDetail 实例对象
     * @return 实例对象
     */
    @Override
    public MedicalDbDetail update(MedicalDbDetail medicalDbDetail) {
        this.medicalDbDetailDao.update(medicalDbDetail);
        return this.queryById(medicalDbDetail.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.medicalDbDetailDao.deleteById(id) > 0;
    }
}
